﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;


namespace Common
{
    public class NHibernateHelper
    {
        private static ISessionFactory sessionFactory = null;

        public static ISession OpenSession()
        {
            if (sessionFactory == null)
            {
                Configuration config = new Configuration();
                try
                {
                    config.Configure();
                    //string[] assemblies = System.Configuration.ConfigurationManager.AppSettings["EntityAssemblies"].Split(',');
                    string[] assemblies = "Basic,Educational".Split(',');
                    for (int i = 0; i < assemblies.Length; i++)
                        config.AddAssembly(assemblies[i]);
                    sessionFactory = config.BuildSessionFactory();
                }
                catch
                {
                    throw;
                }
            }
            try
            {
                return sessionFactory.OpenSession();
            }
            catch
            {
                throw;
            }
        }
    }
}
